package org.yu.register.item;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.NonNullSupplier;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import org.jetbrains.annotations.Nullable;
import org.yu.api.register.LazyItemMenu;
import org.yu.api.register.MenuHolder;
import org.yu.register.CapabilityRegister;
import org.yu.register.capability.MultiDustCapability;
import org.yu.register.capability.MultiDustCapabilityProvider;

import javax.annotation.Nonnull;

public class DanDustItem extends Item {
    public DanDustItem(Properties pProperties) {
        super(pProperties);
    }

    @Nullable
    @Override
    public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
        return new MultiDustCapabilityProvider(MultiDustCapability::new);
    }
    @Nullable
    @Override
    public CompoundTag getShareTag(ItemStack stack) {
        super.getShareTag(stack);
        var tag = stack.getOrCreateTag();
        stack.getCapability(CapabilityRegister.MULTI_DUST).ifPresent(dustCapability -> {
            tag.put("Items",dustCapability.serializeNBT());
        });
        return tag;
    }

    @Override
    public void readShareTag(ItemStack stack, @Nullable CompoundTag nbt) {
        super.readShareTag(stack, nbt);
        if (nbt == null) {
            return;
        }
        stack.getCapability(CapabilityRegister.MULTI_DUST).ifPresent(dustCapability -> {
            dustCapability.deserializeNBT(nbt.getCompound("Items"));
        });
    }
}
